package render

import (
	"html/template"
	"net/http"
)

var htmlContentType = []string{"text/html; charset=utf-8"}

type HTML struct {
	T    *template.Template
	Name string
	Data any
}

func (r HTML) Render(w http.ResponseWriter) error {
	header := w.Header()
	header["Content-Type"] = htmlContentType

	if r.Name == "" {
		return r.T.Execute(w, r.Data)
	}
	return r.T.ExecuteTemplate(w, r.Name, r.Data)
}
